package com.wangzhen.codebase.transfermoney.lock1;

import java.util.ArrayList;
import java.util.List;

public class Allocater {
    private List<Account> list = new ArrayList<>();

    public synchronized boolean apply(Account src, Account dest) {
        if (list.contains(src) || list.contains(dest)) {
            return false;
        } else {
            list.add(src);
            list.add(dest);
            return true;
        }
    }

    public synchronized boolean free(Account src, Account dest) {
        if (list.contains(src)) {
            list.remove(src);
        }
        if (list.contains(dest)) {
            list.remove(dest);
        }
        return true;
    }



}
